package view.impl;

import dao.impl.dishImpl;
import dao.impl.orderImpl;
import prjo.dish;
import prjo.dishMeg;
import prjo.order;
import util.JDBCUtils;
import view.menuDao;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 各个模块的方法
 *
 * @author shkstart
 * @creat 16:17 2022/6/3
 */

public class attribute implements menuDao {
    Scanner scanner = new Scanner(System.in);
    orderImpl orderImpl = new orderImpl();
    dishImpl dishImpl = new dishImpl();

    Connection conn = JDBCUtils.getConnection();

    @Override
    public void Order() {
        System.out.println("*************请  点  菜****************");
        System.out.println("请输入名字：");
        String name = scanner.next();
        //列举菜单
        showDish();

        System.out.println("请输入菜编号第几个：");
        int id = scanner.nextInt();

        System.out.println("请输入点多少份：");
        int num = scanner.nextInt();

        System.out.println("请输入送达时间：");
        int time = scanner.nextInt();

        System.out.println("请输入地址：");
        String address = scanner.next();

        dish dish = (prjo.dish) dishImpl.select(conn, prjo.dish.class, id);
        dishMeg dishMeg = new dishMeg(dish, num);

        orderImpl.addOrder(conn, name, dishMeg, time, address, 0);

        System.out.println("*************点  菜  成  功****************");

        System.out.print("订单：" + dishMeg.toString());
        System.out.println("请输入送达时间：" + time);
        System.out.println("请输入地址：" + address);
        System.out.println("总价：" + dishMeg.getNum() * dish.getPrice());

    }

    @Override
    public void showOrder() {
        List<order> orders = orderImpl.showOrder(conn);
        System.out.println("***********************************************************全部表单********************************************");
        System.out.println("*    id           name          dishMeg           time           address           status        sumPrice ");
        for (order o : orders) {
            System.out.println("\t  " + o.getId() + "           " + o.getName() + "         " + o.getDishMeg() +
                    "       " + o.getTime() + "               " + o.getAddress() + "           " + o.getStatus() + "           " + o.getSumPrice());
        }
        System.out.println("**************************************************************************************************************");
    }

    @Override
    public void getOrder() {
        showOrder();
        System.out.println("\n\t\t\t\t请输入要签收的表单的id：");
        int i = scanner.nextInt();
        orderImpl.getOrder(conn, i);
        System.out.println("\n\t\t\t\t签收完的表单的具体信息：");

        order o = orderImpl.OneOrder(conn, i);
        System.out.println("***********************************************************签收表单********************************************");
        System.out.println("*    id           name          dishMeg           time           address           status        sumPrice ");
        System.out.println("\t  " + o.getId() + "           " + o.getName() + "         " + o.getDishMeg() +
                "       " + o.getTime() + "               " + o.getAddress() + "           " + o.getStatus() + "           " + o.getSumPrice());
        System.out.println("**************************************************************************************************************");
    }

    @Override
    public void deleterOrder() {
        showOrder();
        System.out.println("\n\t\t\t\t请输入要删除的表单的id：");
        int i = scanner.nextInt();
        orderImpl.deleterOrder(conn, i);
        System.out.println("\n\t\t\t\t删除表单之后的Oder表：");

        showOrder();

    }

    @Override
    public void goodToU() {
        System.out.println("！！！！！！！！！！感谢你！！！！！！！！！！");
        aiXin();
    }

    @Override
    public void showDish() {
        ArrayList<dish> dishes = dishImpl.showDish(conn);
        System.out.println("*****************************************************");
        System.out.println("*    id           name          price           nece*");
        for (dish d : dishes) {
            System.out.println("*\t  " + d.getId() + "      " + d.getName() + "           " + d.getPrice() + "               " + d.getNece() + "*");
        }
        System.out.println("*****************************************************");
    }

    /**
     * 打印心形
     */
    public static void aiXin() {
        for (float y = (float) 1.5; y > -1.5; y -= 0.1) {
            for (float x = (float) -1.5; x < 1.5; x += 0.05) {
                float a = x * x + y * y - 1;
                if ((a * a * a - x * x * y * y * y) <= 0.0) {
                    System.out.print("^");
                } else
                    System.out.print(" ");
            }
            System.out.println();
        }
    }
}
